package com.ruoyi.web.controller.squad;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.squadweb.domain.CdkUsageRecords;
import com.ruoyi.squadweb.service.ICdkUsageRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CDK使用记录Controller
 *
 * @author ruoyi
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/system/records")
public class CdkUsageRecordsController extends BaseController
{
    @Autowired
    private ICdkUsageRecordsService cdkUsageRecordsService;

    /**
     * 查询CDK使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(CdkUsageRecords cdkUsageRecords)
    {
        startPage();
        List<CdkUsageRecords> list = cdkUsageRecordsService.selectCdkUsageRecordsList(cdkUsageRecords);
        return getDataTable(list);
    }

    /**
     * 导出CDK使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "CDK使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CdkUsageRecords cdkUsageRecords)
    {
        List<CdkUsageRecords> list = cdkUsageRecordsService.selectCdkUsageRecordsList(cdkUsageRecords);
        ExcelUtil<CdkUsageRecords> util = new ExcelUtil<CdkUsageRecords>(CdkUsageRecords.class);
        util.exportExcel(response, list, "CDK使用记录数据");
    }

    /**
     * 获取CDK使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{sequenceNumber}")
    public AjaxResult getInfo(@PathVariable("sequenceNumber") Long sequenceNumber)
    {
        return success(cdkUsageRecordsService.selectCdkUsageRecordsBySequenceNumber(sequenceNumber));
    }

    /**
     * 新增CDK使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "CDK使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CdkUsageRecords cdkUsageRecords)
    {
        return toAjax(cdkUsageRecordsService.insertCdkUsageRecords(cdkUsageRecords));
    }

    /**
     * 修改CDK使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "CDK使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CdkUsageRecords cdkUsageRecords)
    {
        return toAjax(cdkUsageRecordsService.updateCdkUsageRecords(cdkUsageRecords));
    }

    /**
     * 删除CDK使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "CDK使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sequenceNumbers}")
    public AjaxResult remove(@PathVariable Long[] sequenceNumbers)
    {
        return toAjax(cdkUsageRecordsService.deleteCdkUsageRecordsBySequenceNumbers(sequenceNumbers));
    }
}
